
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@page import="com.tss.util.*"%>
<%@page import="com.jedi.*"%>
<%@page import="com.store.*"%>
<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@include file="../global_var.jsp"%>
<%@include file="../check_login.jsp"%>

<%
User just_user = (User)session.getAttribute("LoginUser");
if (!just_user.hasPower("10803")) {
	out.println(strNoPowerInfo); 
	return;
}
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
User user = (User)session.getAttribute("LoginUser");
List list = null;
String cmd = ParamUtils.getParameter(request,"cmd","");
String cate_id = ParamUtils.getParameter(request,"cate_id","");

String article_title   = ParamUtils.getParameter(request,"article_title","");
String article_content   = ParamUtils.getParameter(request,"article_content","");
String category_id   = ParamUtils.getParameter(request,"category_id","");
String doc_info = ParamUtils.getParameter(request,"doc_info","");
String author_id   = "";
String author_name = "";

ArticleCateMgr cateMgr = new ArticleCateMgr();
ArticleCategory cate = cateMgr.get(cate_id);

if (user != null && !user.getId().trim().equals("")) {
	author_id = user.getId();
	author_name = user.getUserName();
}

String strErr = "";

if (strErr.trim().equals("") && cmd.trim().equals("insert")) {
	if (strErr.trim().equals("") && article_title.trim().equals("")) {
		strErr = "文章标题不能为空!";
	}
	if (strErr.trim().equals("") && article_content.trim().equals("")) {
		strErr = "文章内容不能为空!";
	}
	if (strErr.trim().equals("") && article_content.length() >= 800) {
		strErr = "文章内容不能超过800字符!";
	}
	if (strErr.trim().equals("") && category_id.trim().equals("")) {
		strErr = "请选择文章所属分类!";
	}

	if (strErr.trim().equals("")) {
		Article article = new Article();
		article.setArticleTitle(article_title);
		article.setDocInfo(doc_info);
		article.setAuthorId(author_id);
		article.setAuthorName(author_name);
		article.setArticleContent(article_content);
		article.setCategoryId(category_id);
		article.setIssueTime(TSSDate.fullTime());
		article.setHit(0);
		article.insert();
		if (article.hasErr()) strErr = article.getErrHtml();
	}
}
%>
<html>
<head>
   <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link href="style/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript">
function chk_submit() {
	var oForm = document.operatorForm;
	if (oForm.article_title.value == "") {
		alert("文章标题不能为空!");
		oForm.article_title.focus();
		return false;
	}
	if (oForm.article_content.value == "") {
		alert("文章内容不能为空!");
		oForm.article_content.focus();
		return false;
	}
	if (oForm.category_id.selectedIndex < 0) {
		alert("请选择文章所属分类!");
		oForm.category_id.focus();
		return false;
	}
	oForm.cmd.value = "insert";
	return true;
}

function upload_file() {
	var oForm = document.operatorForm;
	var r = window.showModalDialog('../selectFrm.htm','knowledge_mgt/upload_article.jsp','dialogHeight: 200px;dialogWidth: 300px; center: yes; status:no;help: no');
	if(r && r != "") {
		oForm.doc_info.value = r;
	}
}
</script>
</head>
<body  leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td style="padding-left:25px;">
	 <form name="operatorForm" method="post" onsubmit="return chk_submit();">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td height="31" valign="top" background="images/title_bk_01.gif" style="padding-left:10px;padding-top:6px;">
            
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="50%" style="color:#FFFFFF;font-size:13px;">
                  <b>知识库</b> -&gt; 
                  <b>文章添加</b>
                </td>
                <td width="50%" align="right" style="padding-right:10px;">&nbsp;
                  <span onclick="right_menu_clk('know_article_list.jsp?parent_id=<%=cate_id%>');" style="cursor:hand;color:#FFFFFF;font-size:12px;text-de--ation: underline;">文章列表</span>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr> 
          <td height="100" align="center" valign="top" style="padding-top:20px;padding-bottom:10px;">
            <table width="80%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
             
              <%if (!strErr.trim().equals("")) {%>
              <tr> 
                <td width="30%" height="28" align="right" bgcolor="#858585"><font color="#FFFFFF">错误提示：</font></td>
                <td bgcolor="#EDEDF0"><font color=red><%=strErr%></font>&nbsp;</td>
              </tr>
              <%}%>
              <tr> 
                <td width="30%" height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">文章标题：</font></td>
                <td bgcolor="#D7D7DB"><input name="article_title" type="text" class="inputbox" value="<%=article_title%>" size="30" maxlength="50"></td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">文章内容：</font></td>
                <td bgcolor="#EDEDF0">
                  <textarea name="article_content" cols="40" rows="5"><%=article_content%></textarea>
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">文档附件：</font></td>
                <td bgcolor="#EDEDF0">
                  <input type="text" name="doc_info" value="<%=doc_info%>" size="30" maxlength="50" style="background-color:#EDEDE8" readonly="readonly"> &nbsp; 
                  <input type="button" value="上传附件" class="inputButton" onclick="upload_file();"> 
                </td>
              </tr>
              <tr>
                <td height="24" align="right" bgcolor="#858585"><font color="#FFFFFF">文章所属分类：</font></td>
                <td bgcolor="#EDEDF0">
                  <select name="category_id">
                    <%
                    if (cate != null && !cate.getId().equals("")){
                    	if (cate.isLeaf()) {
                    %>
                    <option value="<%=cate.getId()%>" selected><%=cate.getCategoryName()%></option>
                    <%
                    	}else{
                    		list = cateMgr.get(" and parent_id = '" + cate_id + "' and is_leaf = 1","order_id");
                    		if (list != null && list.size() > 0) {
                    			for(int i=0;i<list.size();i++) {
                    				ArticleCategory item = (ArticleCategory)list.get(i);
                    %>
                    <option value="<%=item.getId()%>"<%if (item.getId().equals(category_id)){%> selected<%}%>><%=item.getCategoryName()%></option>
                    <%
                    			}
                    		}
                    	}
                    }
                    %>
                  </select>
                </td>
              </tr>
              <tr> 
                <td height="24" align="right" bgcolor="#EDEDF0">&nbsp;</td>
                <td bgcolor="#EDEDF0"> 
                  <input type="submit" name="submit" value="提 交" class="inputButton"> 
                  <input type="reset" name="reset" value="重 写" class="inputButton"> 
                  <input type="hidden" name="cmd" value=""> 
                </td>
              </tr>
             
            </table>
          </td>
        </tr>
      </table>
	   </form>
    </td>
  </tr>
</table>
<%if (cmd.equals("insert") && strErr.trim().equals("")){%>
<script language="javascript">
alert("文章信息添加成功!");
location.href = "know_article_list.jsp?parent_id=<%=cate_id%>";
</script>
<%}%>
</body>
</html>